package shopping.demo.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import shopping.demo.entities.Goods;

import java.util.List;

@Repository
@Mapper
public interface GoodsDao {
    @Select("select * from goods")
    public List<Goods> findAll();

    @Select("select * from goods where id=#{id}")
    public Goods findById(Integer id);

    @Select("select * from goods where `kill`=1")
    public List<Goods> findKilled();

    @Update("update goods set price=#{price} where id=#{id}")
    public int changePrice(Integer id, Integer price);

    @Update("update goods set count=count-#{count} where id=#{id}")
    public int countDown(Integer id,Integer count);

    @Update("update goods set `kill`=1 where id=#{id}")
    public int setKilled(Integer id);

    @Delete("delete from goods where id=#{id}")
    public int deleteById(Integer id);

    @Insert("insert into goods values(#{id},#{name},#{count},#{price},0)")
    public int insertGoods(Integer id, String name, Integer count, Integer price);
}
